home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 12.4 KB | 388 lines | [TEXT/MPS ] |
- // UFile.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UFILE__
- #define __UFILE__
-
- // MacApp
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __USCRIPTABLEOBJECT__
- #include "UScriptableObject.h"
- #endif
-
- // Toolbox
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // TFile
- //----------------------------------------------------------------------------------------
-
- const OSType kFolderType = 'fold';
- const OSType kFolderCreator = '\?\?\?\?';
-
- const OSType kGenericType = 'TEXT';
- const OSType kGenericCreator = '\?\?\?\?';
-
- enum ResourceUsage
- {
- needResourceFork,
- preferResourceFork,
- noResourceFork
- };
-
- const Boolean kUsesDataFork = TRUE;
- const ResourceUsage kUsesRsrcFork = preferResourceFork;
- const Boolean kDataOpen = TRUE;
- const Boolean kRsrcOpen = TRUE;
-
-
- class TFile : public TObject, public MScriptableObject
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TFile();
- // Constructor
-
- void IFile(OSType itsFileType,
- OSType itsCreator,
- Boolean usesDataFork,
- ResourceUsage usesRsrcFork,
- Boolean keepsDataOpen,
- Boolean keepsRsrcOpen);
- // Initialization method for TFile
-
- virtual ~TFile();
-
- //------------------------------------------------------------------------------------
- // File Specification
- //------------------------------------------------------------------------------------
-
- virtual void Specify(const FSSpec& theFile);
- // Specify the file by its FSSpec.If the file has already opened a file, Specify
- // will attempt to close the file before re-identifying the file
-
- virtual void SpecifyWithStandardFileReply(const StandardFileReply& itsReply);
- // Specify a file with the information returned from CustomGetFile/CustomPutFile
- // This will also set the filetype and scripttag, and indicates if the
- // file is a stationery pad.
-
- virtual OSErr SpecifyWithSFReply(const SFReply& itsReply);
- // Specify a file with the information returned from SFPGetFile/SFPPutFile
- // This will also set the filetype.
-
- virtual OSErr SpecifyWithAlias(AliasHandle alias);
- // Similar to TFile::Specify except the file is specified with an alias. Also queries
- // the finder information to determine the real filetype, creator, and
- // whether or not the file pointed to by the alias is a stationery pad.
-
- virtual void SpecifyWithFile(TFile* aFile);
- // Make this file reference the same file as aFile.
-
- virtual OSErr SpecifyWithTrio(short volRefNum, long dirID, const CStr63& name);
- // Specify a file by volrefnum, dir ID, and filename. If dirID is zero, it then
- // volRefNum is assumed to be a working directory and will be resolved to a
- // directory ID
-
- //------------------------------------------------------------------------------------
- // Creating/Opening/Closing/Deleting
- //------------------------------------------------------------------------------------
-
- virtual OSErr CloseFile();
- // Close the forks of the file irrespective of the fKeepOpen fields
-
- virtual OSErr CloseFileIfNotKeptOpen();
- // Close the file respecting whether or not the data and resource fork should
- // be left open.
-
- virtual OSErr CloseDataFork();
- // Close the data fork. Called by CloseFile
-
- virtual OSErr CloseRsrcFork();
- // Close the rsrc fork. Called by CloseFile
-
- virtual OSErr CreateFile();
- // Create the file
-
- virtual OSErr CreateDataFork();
- // Create the data fork of the file. Called by CreateFile
-
- virtual OSErr CreateRsrcFork();
- // Create the rsrc fork of the file. Called by CreateFile
-
- virtual OSErr DeleteFile();
- // Close the file and delete it.
-
- virtual OSErr OpenFile();
- // Open the forks of the file irrespective of the fKeepOpen fields
-
- virtual OSErr OpenFileIfKeptOpen();
- // Open the file with the fDataPermission and fRsrcPermission respecting the
- // fKeepOpen fields
-
- virtual OSErr OpenDataFork(SignedByte permission);
- // Open the data fork of the file. Called by OpenFile
-
- virtual OSErr OpenRsrcFork(SignedByte permission);
- // Open the rsrc fork of the file. Called by OpenFile
-
-
- //------------------------------------------------------------------------------------
- // file attributes
- //------------------------------------------------------------------------------------
-
- virtual OSErr GetAlias(AliasHandle& alias);
- // Return the file specification as an alias handle
-
- virtual OSErr GetCatInfo(CInfoPBRec& cInfo);
- // Return the catalog information about the this file
-
- virtual long GetCreationDate();
- // Date the file was created
-
- virtual OSErr GetDataLength(long& length);
- // Return the length of the data fork
-
- virtual OSErr GetDataMark(long& mark);
- // Return the position of the mark in the data fork
-
- virtual long GetDirID();
- // Return the directory ID stored in the FSSpec
-
- virtual OSErr GetFileCreator(OSType& creator);
- // Return the creator of the file as found in the finder info
-
- virtual OSErr GetFileInfo(HParamBlockRec& pb);
- // Return all the information the file manager provides
-
- virtual void GetFileSpec(FSSpec& theFileSpec);
- // Return its file specification record
-
- virtual OSErr GetFileType(OSType& fileType);
- // Return the type of the file as found in the finder info
-
- virtual OSErr GetFinderInfo(FInfo& fndrInfo);
- // Return finder information about the file
-
- virtual OSErr GetFinderInfo(FInfo& fndrInfo, FXInfo& itsFXInfo, Boolean& isDirectory);
- // Return finder information about the file
- // IF isDirectory returns TRUE (indicating that it's a directory)
- // returns DInfo in fndrInfo and DXInfo in itsFXInfo
- // ELSE
- // returns FInfo in fndrInfo and FXInfo in itsFXInfo
-
- virtual long GetModificationDate();
- // Return the date the file was last modified
-
- virtual void GetName(CStr63& name);
- // Return the name of the file
-
- virtual OSErr GetPathName(CStr255& pathName);
- // Return the MPW style path name of the file
-
- virtual OSErr GetPhysicalSize(long& dataSize, long& rsrcSize);
- // Returns the physical size in bytes of the data and resource fork
-
- virtual OSErr GetScript(ScriptCode& theScript);
- // Returns the script code as stored in the extended finder info
-
- virtual OSErr SetModificationDate(long modificationDate);
- // Sets the modification date of the file.
-
- virtual OSErr SetCreationDate(long creationDate);
- // Sets the creation date of the file.
-
- virtual OSErr SetFinderInfo(const FInfo& fndrInfo);
- // Sets the finder information for the file.
-
-
- //----------------------------------------------------------------------------------------
- // Volume attributes
- //----------------------------------------------------------------------------------------
-
- virtual OSErr FlushVolume();
- // Flush the volume to force any changes to take place
-
- virtual OSErr GetBlockSize(long& blockSize);
- // Return the size of allocated blocks on the volume
-
- virtual OSErr GetFreeBlocks(long& freeBlocks);
- // Return the number of free blocks on the volume
-
- virtual OSErr GetVolumeInfo(HParamBlockRec& pb);
- // Return all information provided by the file manager on the volume
-
- virtual OSErr GetVolumeName(CStr63& name);
- // Return the name of the volume
-
- virtual short GetVolRefNum();
- // Return the volume reference number stored in the FSSpec
-
- virtual OSErr ExchangeFiles(TFile* aFile);
- // Exchange the contents of this with the contents of another file maintaining the
- // file id
-
- virtual Boolean IsDataForkOpen();
- // True if the data fork of the file is open
-
- virtual Boolean IsModified();
- // Checks fModDate to determine if file changed
-
- virtual Boolean IsRsrcForkOpen();
- // True if the resource fork of the file is open
-
- virtual Boolean IsSameFile(TFile* aFile);
- // Does this file refer to the same file as aFile?
-
- virtual Boolean IsStationery();
- // True if this file is a stationery pad
-
- virtual OSErr IsVolumeLocked(Boolean& locked);
- // Returns true if the volume is hardware or software locked
-
- virtual Boolean HasDataFork();
- // Returns true if file has a data fork
-
- virtual Boolean HasRsrcFork();
- // Returns true if file has a resource fork
-
- virtual Boolean HasValidFileSpec();
- // Returns true if the filespec has been set to some value other than
- // the initialized value.
-
- virtual void Modified();
- // Update fModDate to the value stored by the finder
-
- virtual OSErr MoveAndRename(const FSSpec& dest);
- // Move the file to the new destination and give it a new name
-
- virtual OSErr ReadData(void* buffer, long& count);
- // Read count bytes from the data fork into buffer
-
- virtual OSErr ReadUntil(void* buffer, long& count, char untilChar);
- // Read bytes from the supplied buffer until the stop character untilChar
- // is found. Returns the number of bytes actually read in count.
-
- virtual OSErr RenameFile(const CStr63& newName);
- // Rename the file to the specified name
-
- virtual OSErr SetCatInfo(CInfoPBRec& cInfo);
- // Set the catalog information about this file. The file reference portion of the
- // record is supplied by fFileSpec.
-
- virtual OSErr SetDataLength(long length);
- // Set the length of the data fork
-
- virtual OSErr SetDataMark(long mark, short fromWhere);
- // Set the position of the mark in the data fork
-
- virtual OSErr SetFileInfo( HParamBlockRec& pb);
- // Set the file information about this file. The file reference portion of the
- // record is supplied by fFileSpec.
-
- virtual void SetName(const CStr63& newName);
- // Sets the name field of the filespec but doesn't rename the file
-
- virtual void SetPermissions(SignedByte dataPermission,
- SignedByte rsrcPermission);
- // Set the fDataPermission and fRsrcPermission fields of the file
-
- virtual OSErr SetScript(ScriptCode theScript);
- // Sets the script code stored in the extended finder info
-
- Boolean UpdateFileSpec();
- // Update the file's FSSpec and notify if a change was required.
-
- virtual OSErr UpdateResource();
- // Update the resource referenced by fRsrcRefNum
-
- virtual short UseResource();
- // Returns the current resource file and set itself as the current file
-
- virtual OSErr WriteData(const void* buffer, long& count);
- // Write count bytes from buffer to the data fork
-
- //----------------------------------------------------------------------------------------
- // Scripting Support
- //----------------------------------------------------------------------------------------
-
- virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType);
-
- virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty);
-
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
-
- FSSpec fFileSpec; // volume/ directory/filename
-
- OSType fFileType; // file type
-
- OSType fCreator; // creator ID
-
- long fModDate; // file mod date when last read/ saved
-
- short fDataRefNum; // Reference for reading/ writing to data
- // fork
-
- short fRsrcRefNum; // Reference for reading/ writing to
- // resource fork
-
- ScriptCode fScriptTag; // The script the file was created with
-
- ResourceUsage fUsesRsrcFork; // A value of need or prefer indicates
- // the file uses its resource fork
-
- SignedByte fDataPermission; // Permissions used when opening the data
- // fork
-
- SignedByte fRsrcPermission; // Permissions used when opening the
- // resource fork
-
- Boolean fStationery; // True if this is stationery
-
- Boolean fUsesDataFork; // True if the file uses its data fork
-
- Boolean fKeepDataOpen; // Will the data fork be left open?
-
- Boolean fKeepRsrcOpen; // Will the rsrc fork be left open?
-
- protected:
- AliasHandle fAlias;
- };
-
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
- extern TFile* NewFile(OSType itsFileType,
- OSType itsCreator,
- Boolean usesDataFork,
- ResourceUsage usesRsrcFork,
- Boolean keepsDataOpen,
- Boolean keepsRsrcOpen);
- // A convenience function. Create a TFile, initialize it, and return a reference to
- // it. Signals Failure if it cannot allocate the object.
-
-
- #endif
-
-
-